<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <script type="text/javascript">
    window.onload = function () {
      var form1 = document.getElementById("form1");

      form1.onsubmit = function () {

        if (form1.username.value.length >= 4 && form1.username.value.length <= 6) {
          if (form1.password.value.length == 6) {
            if (form1.confirm.value.length == 6 && form1.password.value == form1.confirm.value) {
              return true;
            } else {
              alert("确认密码必须和密码一致 并且 长度为6");

              return false;
            }

          } else {
            alert("密码长度必须为6位");
            return false;
          }
        } else {
          alert("用户名长度必须在4-6之间");
          alert("1111111" + form1.username.value.length);
          return false;
        }

      }

    }
  </script>
</head>
<body>
<form action="ok.html" id="form1">
  用户名:<input type="text" name="username"><br/>
  密码：<input type="password" name="password"><br/>
  确认:<input type="password" name="confirm"><br/>
  电子邮件:<input type="email" name="email"><br>
  <input type="submit" value="注册用户"><br/>
</form>
</body>
</html>
